package com.taotao.job.conf;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class RedissonConfig {

	private String serverAddress;
	private String password;
	private int database;
	private int poolSize;



	@Bean(destroyMethod = "shutdown")
	RedissonClient redisson() throws IOException {
		Config config = new Config();
		//config.useClusterServers().addNodeAddress("127.0.0.1:6379");
		SingleServerConfig c = config.useSingleServer();
		c.setAddress("redis://"+serverAddress);
		c.setPassword(password);
		c.setDatabase(database);
		c.setConnectionPoolSize(poolSize);

		return Redisson.create(config);
	}
}
